<template>
  <a-card :title="t('视图信息')" size="small">
    <a-form :label-col="{ span: 9 }" :wrapper-col="{ span: 15 }">
      <a-form-item :label="t('视图名称')" v-bind="validateInfos.viewName">
        <a-input
          v-model:value="modelRef.viewName"
          :placeholder="t('请输入视图名称')"
          allow-clear
        ></a-input>
      </a-form-item>
      <a-form-item :label="t('视图编码')" v-bind="validateInfos.viewCode">
        <a-input
          v-model:value.trim="modelRef.viewCode"
          :placeholder="t('请输入视图编码')"
          @change="handleUpperCase"
          allow-clear
        ></a-input>
      </a-form-item>
      <a-form-item :label="t('视图状态')" v-bind="validateInfos.viewStatus">
        <a-switch
          v-model:checked="modelRef.viewStatus"
          checked-value="Y"
          un-checked-value="N"
          :checked-children="t('有效')"
          :un-checked-children="t('无效')"
        ></a-switch>
      </a-form-item>
      <a-form-item :label="t('发布状态')" v-bind="validateInfos.publishStatus">
        <a-select
          :value="model?.publishStatus || 'N'"
          :options="[
            { label: () => t('已发布'), value: 'Y' },
            { label: () => t('未发布'), value: 'N' },
          ]"
          disabled
        ></a-select>
      </a-form-item>
      <a-form-item :label="t('视图描述')">
        <a-textarea
          v-model:value="modelRef.viewDesc"
          :placeholder="t('请输入视图描述')"
          :rows="2"
          allow-clear
        ></a-textarea>
      </a-form-item>
    </a-form>
  </a-card>
</template>
<script lang="ts" setup>
import { inject } from "vue";
import type { QueryResult, ViewParams } from "@/api/low-code/view/typing";
import { useI18n } from "vue-i18n";
import { MODEL_REF } from "..";
import type { Form } from "ant-design-vue";

interface Props {
  /**行数据 */
  model: QueryResult;
  /**弹窗 */
  open: boolean;
  /**校验 */
  validateInfos: ReturnType<typeof Form.useForm>["validateInfos"];
}
defineProps<Props>();
const { t } = useI18n();
const modelRef = inject<ViewParams>(MODEL_REF);
/**视图编码转大写 */
const handleUpperCase = () => {
  modelRef.viewCode = modelRef.viewCode.toUpperCase();
};
</script>
